import tensorflow as tf
import numpy as np

loss_ce1 = tf.losses.categorical_crossentropy([1,0],[0.6,0.4])
loss_ce2 = tf.losses.categorical_crossentropy([1,0],[0.8,0.4])
loss_ce3 = tf.losses.categorical_crossentropy([1,0],[0.6,0.2])
print("loss_ce1:",loss_ce1)
print("loss_ce2:",loss_ce2)
print("loss_ce3:",loss_ce3)

# softmax与交叉熵结合
y_= np.array([[1, 0, 0], [0, 1,0],[0, 0,1],[1, 0, 0], [0,1,0]])
y = np.array([[12,3,2],[3,10,1],[1,2, 5],[4, 6.5,1.2],[3,6,1]])
y_pro = tf.nn.softmax(y)
loss_ce1 = tf.losses.categorical_crossentropy(y_,y_pro)
loss_ce2 = tf.nn.softmax_cross_entropy_with_logits(y_,y)
print('分步计算的结果:ln', loss_ce1)
print('结合计算的结果:ln', loss_ce2)
